/*
 * Created on 29/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view.elm_solution_view;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.text.Position;

import br.ufmg.dees.insane.ui.rich.learn.learn_controller.DisplacementsController;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.GridFrameDisplacementsController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdMenu;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnViewState;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.elm_solution_view.command.GetElementDisplacementsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.elm_solution_view.command.GetElementStrainCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.elm_solution_view.command.GetElementStressCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.elm_solution_view.command.Help7Command;

/**
 * @author Francisca
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ElmSolutionView extends LearnView {  
	
	//  No da arvore: ElmSolution
	private Command elementStressCmd = new GetElementStressCommand(parent);
	private Command elementStrainCmd = new GetElementStrainCommand(parent);
	private Command elementDisplacementsCmd = new GetElementDisplacementsCommand(parent);
	private Command help7Cmd = new Help7Command(parent);
	
	//	No ElmSolution
    private CmdMenu itemElementStress = new CmdMenu("Element Stress", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdMenu itemElementStrain = new CmdMenu("Element Strain", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdMenu itemElementDisplacements = new CmdMenu("Element Displacements", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdMenu itemHelp7 = new CmdMenu("Help", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));

    
    //No ElmSolution
    private CmdButton elementStress = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdButton elementStrain = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdButton elementDisplacements = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdButton help7 = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
   
    private JMenu menuElementSolution = new JMenu("Element Solution");
    protected JToolBar elementSolutionToolBar = new JToolBar();
    
	public ElmSolutionView(LearnInterface parent){
	    super(parent);
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new DisplacementsController(this));
		
		String gAnlType = this.getController().getModel().getGlobalAnalysisModel().getType();
		
		if (!(gAnlType.equals("Grid"))) {
			super.setController(new DisplacementsController(this));
		} else {
			super.setController(new GridFrameDisplacementsController(this));
		}
		
		
		//Setting menu ElmSolution
		menuElementSolution.add(itemElementStress);
		itemElementStress.setCommand(elementStressCmd);
		itemElementStress.setEnabled(false);
		itemElementStress.setMnemonic(KeyEvent.VK_E);
		itemElementStress.addActionListener(parent);
        
		menuElementSolution.add(itemElementStrain);
		itemElementStrain.setCommand(elementStrainCmd);
		itemElementStrain.setEnabled(false);
		itemElementStrain.setMnemonic(KeyEvent.VK_A);
		itemElementStrain.addActionListener(parent);
		
		menuElementSolution.add(itemElementDisplacements);
		itemElementDisplacements.setCommand(elementDisplacementsCmd);
		itemElementDisplacements.setEnabled(false);
		itemElementDisplacements.setMnemonic(KeyEvent.VK_D);
		itemElementDisplacements.addActionListener(parent);
		
		menuElementSolution.add(itemHelp7);
        itemHelp7.setCommand(help7Cmd);
        itemHelp7.setEnabled(false);
        itemHelp7.setMnemonic(KeyEvent.VK_H);
        itemHelp7.addActionListener(parent);
        
        elementSolutionToolBar.add(elementStress);
        elementStress.setToolTipText("Element Stress");
        elementStress.addActionListener(parent);
        elementStress.setCommand(elementStressCmd);
        
        elementSolutionToolBar.add(elementStrain);
        elementStrain.setToolTipText("Element Strain");
        elementStrain.addActionListener(parent);
        elementStrain.setCommand(elementStrainCmd);
        
        elementSolutionToolBar.add(elementDisplacements);
        elementDisplacements.setToolTipText("Element Displacements");
        elementDisplacements.addActionListener(parent);
        elementDisplacements.setCommand(elementDisplacementsCmd);
               
        elementSolutionToolBar.add(help7);
		help7.setToolTipText("Help");
		help7.addActionListener(parent);
		help7.setCommand(help7Cmd);
        
	}
	
	public void init(){
	    super.init();
			parent.getMenuPanel().removeAll();
			parent.getMenuPanel().add(menuFile);
			itemSave.setEnabled(true);
			itemSaveAs.setEnabled(true);
			itemClose.setEnabled(true);
			itemPrint.setEnabled(true);
			menuExport.setEnabled(true);
			menuImport.setEnabled(true);
			parent.getMenuPanel().add(menuEdit);
			parent.getMenuPanel().add(menuView);
			parent.getMenuPanel().add(menuElementSolution);
			menuElementSolution.setEnabled(true);
			itemElementStress.setEnabled(true);
			itemElementStrain.setEnabled(true);
			itemElementDisplacements.setEnabled(true);
			itemHelp7.setEnabled(true);
			parent.getMenuPanel().add(menuSettings);
			parent.getMenuPanel().add(menuHelp);
	        
			parent.getToolPanel().removeAll();
			parent.getToolPanel().add(fileToolBar);
			save.setEnabled(true);
			saveAs.setEnabled(true);
			print.setEnabled(true);
			delete.setEnabled(false);
			parent.getToolPanel().add(editToolBar);
			parent.getToolPanel().add(zoomToolBar);
			parent.getToolPanel().add(elementSolutionToolBar);
			elementStress.setEnabled(true);
			elementStrain.setEnabled(true);
			elementDisplacements.setEnabled(true);
			help7.setEnabled(true);
							
	        parent.getConsolePanel().setVisible(true);
			
			grid.setEnabled(true);
			snap.setEnabled(true);
			
			this.getDrawingArea().setRepainting(false);
			this.getDrawingArea().repaint();
	        
			parent.getConsoleHandler().setToCommandMode();
			parent.getConsoleHandler().setKeybCommand(null);
			
			this.setStateButtons();
			
			parent.getTree().setEnabled(true);
			parent.getTree().setSelectionPath(parent.getTree().getNextMatch("Element Solution", 0, Position.Bias.Forward));
			
			this.getController().compose();

			parent.getDrawPanel().removeAll();
			parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
			this.getDrawingArea().removeAllCommands();
			this.getDrawingArea().setClickedCommand(new SelectCommand(parent));
			this.getDrawingArea().setCursor();
			parent.getDrawPanel().repaint();
			parent.getDrawPanel().updateUI();
			
			parent.getJMenuBar().updateUI();
			parent.repaint();
	    }   

	public  JFrame getInterface(){
    	return parent;
    }
    
	public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }

}
